<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script>
   var stuno=window.location.search;
   //alert("jq:"+$.param());
   stuno=stuno.substring(1);
   alert(stuno);
    
   $(function(){
	   $.get("gradeAjaxServlet",function(data){
			 var g=$("#gradeid");
			 $.each(data,function(i,d){
				 g.append(new Option(d.gname,d.id));
				 //g.append("<option value=''></option>");
			 });
		});
	   //ajax,拿到student
	   //有隐患，可能年级没有拿到，学生信息拿到了，导致年级的默认选中有问题
	   $.get("findStudent",{stuno:stuno},function(p){
		   for(var attr in p){
			   $("[name="+attr+"]").val(p[attr]);
		   }
		   //特殊的，再特殊处理
		   $(":radio[name=sex][value='"+p.sex+"']").prop("checked",true);
	   	   $("img[id=idcardpic]").attr("src",p.idcardpic);	
	   });
	   $("#save").click(function(){
		   //$("form").serialize();
		   var f=$("form")[0];//转换成dom对象
      
        	var mydata=new FormData(f);
        	 $.ajax({
                 url:"updateStudentServlet",
                 type:"POST",
                 data:mydata,
                 contentType:false,
                 processData:false,
                 success:function(d){alert(d);f.reset();}
             });
		   return false;
	   });
   });
 
   
</script>
</head>
 <body>
  <h2>学生信息</h2>
  <form action="doUpdatestudent.jsp" method="post" enctype="multipart/form-data">
		<p>
			<label>学号:</label> <input type="text" name="stuno"
				readonly="readonly"  value="<%=s.getStuno()%>" />
		</p>
		<p>
			<label>姓名:</label> <input type="text" name="sname"
				required="required" value="<%=s.getSname()%>" />
		</p>
		<p>
			<label>性别:</label> <input type="radio" required name="sex" value="男" />男
			<input type="radio" required name="sex" value="女" />女 <input
				type="radio" required name="sex" value="妖" /> 妖

			
		</p>
		<p>
			<label>电话:</label> <input type="text" name="telephone"
				required="required" value="" />
		</p>
		<p>
			<label>qq:</label> <input type="text" name="qq"
				value="" />
		</p>
		<p>
			<label>微信:</label> <input type="text" name="wechat"
				value="" />
		</p>

		<p>
			<label>年级:</label>
			
			<select name="gradeid" id="gradeid">

			</select>


		</p>
		<p>
			<label>入学日期:</label> <input type="text" name="enterdate"
				value="" />
		</p>
		<p>
			<label>来自哪个城市:</label> <input type="text" name="fromcity"
				required="required" value="" />
		</p>
		<p>
			<label>生日:</label> <input type="text" name="birthday"
				required="required"
				value="" />
		</p>
		<p>
			<label>地址:</label> <input type="text" name="address"
				value="" />
		</p>
		<p>
			<label>密码:</label> <input type="text" name="pass" required="required"
				value="" />
		</p>
		<p>
			<label>身份证照片</label> <input type="file" name="idcardpic"
				placeholder="更换图片" /> <img src=""
				alt="没有图片" height="200px" width="200px" />
		</p>
		<p>
			<button type="submit" class="page-btn" id="save" name="save">确认</button>
		</p>
	</form>

</body>  
</html>
